#ifndef FIR_FIRMANAGER_H_
#define FIR_FIRMANAGER_H_

#include <Windows.h>
#include "firchesstype.h"
#include "firmove.h"

class FIRPlayer;

typedef unsigned char Byte;

class FIRManager {
private:
    // the unique instance of class FIRManager
    static FIRManager instance;

    // the two players of this game
    FIRPlayer * player1;
    FIRPlayer * player2;

    // current player order
    FIRChessType order;

    // last move
    FIRMove last_move;

    // true if game is started
    bool started;

    // the game thread
    HANDLE game_thread;
    DWORD thread_id;
public:
    void Init();
    static FIRManager& Instance();

    void StartGame(FIRPlayer * p1, FIRPlayer* p2);
    void GameOver();

    void EndCurrentGame();

    static DWORD WINAPI GameLoop(LPVOID lpParam);

    FIRMove GetLastMove() const;

    bool Next();

    FIRChessType GetCurrentOrder();

    DWORD GetThreadId();
    HANDLE GetThreadHandler();


    // the chess matrix
    // TODO: change matrix to non-static parameter and provide a interface
    // to modify matrix.
    static Byte matrix[15][15];


private:
    bool IsGameOver(FIRMove move);

};

#endif // FIR_FIRMANAGER_H_